package com.enlorenz.common.geo.analyzer.distance.calc;

import com.copote.adc.paramproc.IStatusModelParamProc;
import com.enlorenz.common.geo.analyzer.distance.IDataCalculator;
import com.enlorenz.common.geo.util.GeographyUtil;
import com.enlorenz.core.objectmodel.entity.IStatus;

/**
 * 点距离计算
 * @author Karma
 *
 */
public class PointDisCacl implements IDataCalculator{
	private IStatus preStatus;
	private double totalDis=0;
	private IStatusModelParamProc statusModelParamProc;
	public void setStatusModelParamProc(IStatusModelParamProc statusModelParamProc) {
		this.statusModelParamProc = statusModelParamProc;
	}
	public IStatusModelParamProc getStatusModelParamProc() {
		return statusModelParamProc;
	}
	@Override
	public void doIterator(int total, int index, IStatus status) {
		if(statusModelParamProc.isGpsLock(status)){
			if(null == preStatus){
				preStatus=status;
			}else{
				Double dis=GeographyUtil.computerDistanceFromPoint(preStatus,status);
				if(status.getSpeed().equals("0") && preStatus.getSpeed().equals("0")){
					dis=0.0;
				}
				
				if(preStatus.getLon().equals("0") ||  preStatus.getLat().equals("0")
						||status.getLon().equals("0") ||  status.getLat().equals("0")){
					dis=0.0;
				}
				
				
				totalDis+=dis;
				preStatus=status;
			}
		}
	}

	@Override
	public String getResult() {
		return String.valueOf(totalDis);
	}

}
